/*
 * Computations.java
 *
 * Created on January 19, 2008, 10:15 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package wisp.dataObjects;



import java.util.*;
import java.util.Vector;
import java.util.Iterator;
/**
 *
 * @author Shelley Chuateco Co
 */
public class StatsCompPVP 
{
    
    /** Creates a new instance of Computations */
    public StatsCompPVP() {    }
    
    
    public int compCurHP(String cName, Item i, SkillType skillT, WispCharacter wc)
    {
        Double d = new Double(0);
        int value = 0, ret = 0, skb = 0;
        int cHP = 0;
        
        if (i != null)
            d = i.getHp() * wc.getCHP();
        cHP = d.intValue();
        
        if (skillT != null)
        {
            d = skillT.getCurrentHP() * wc.getCHP();
            skb = d.intValue();
        }
       
        value = wc.getCHP();
        System.out.println(value+" " +" " + cHP+" " + skb);
        ret = value + cHP + skb;
        
        System.out.println("[CURRENT HP] : "+ret);
        return ret;
    }
    
    public int compCurMP(String cName, Item i, SkillType skillT, WispCharacter wc)
    {
        Double d = new Double(0);
        int value = 0, ret = 0, skb = 0;
        int cMP = 0;
        
        if (i != null)
            d = i.getMp() * wc.getCMP();
        cMP = d.intValue();
             
        if (skillT != null)
        {
            d = skillT.getCurrentMP() * wc.getCMP();
            skb = d.intValue();
        }
       
        value = wc.getCMP();
        ret = value + cMP + skb;

        System.out.println("[CURRENT MP] : "+ret);
        return ret;
    }
    
    public int compMaxHP(String cName, Item i, SkillType skillT, WispCharacter wc)
    {
        int ret = 0, skb = 0;
        String temp = null;
        Double d = new Double(0);
        
        if (i != null)
            d = i.getMhp();
        int mhp = d.intValue() * wc.getMHP();
        
        ret = mhp + skb + wc.getMHP();
        
        System.out.println("[MAX HP] : "+ret);
        return ret;
    }
    
    public int compMaxMP(String cName, Item i, SkillType skillT, WispCharacter wc)
    {
        int ret = 0, skb = 0;
        String temp = null;
        Double d = new Double(0);
        
        if (i != null)
            d = i.getMmp();
        int mmp = d.intValue() * wc.getMMP();
        
        if (skillT != null)
        {
            d = skillT.getMaxMP() * wc.getMMP();
            skb = d.intValue();
        }
        
        ret = mmp + skb + wc.getMMP();
        System.out.println("[MAX MP] : "+ret);
        return ret;
    }
    
    public int heal(double bonus, int slvl, int clvl, Statistics wcs)
    {
        double f1 = clvl/2;
        if (f1 < 1)
            f1=1;
        double f2 = slvl * (wcs.getCInt()+wcs.getSpr()/2);
        
        int ret = (int) Math.ceil((f1 * f2) * (1 + bonus));
        System.out.println("[HEAL] : "+ret);
        return ret;
    }
    
    public double compHPR(String cName, Item i, SkillType skillT, Statistics wcs)
    {
        double value = 0.0, skb = 0.0, it = 0.0, ret=0.0;
        double hpr = wcs.getHpGR();
        int vit = wcs.getVit();
        
        if (i != null)
            it = i.getHpr();
        if (skillT != null)
            skb = skillT.getHpgr();
        
        value = hpr * (1.05 + (vit * 0.01));
        ret = (value + it + skb);
        System.out.println("[HP REGEN RATE] : "+ret);
        return ret;
    }
    
    public double compMPR(String cName, Item i, SkillType skillT, Statistics wcs)
    {
        double value = 0.0, val = 0.0, it = 0.0, ret=0.0;
        double mpr = wcs.getMpGR();
        int spr = wcs.getSpr();//to be changed
        
        if (i != null)
            it = i.getMpr();
        value = mpr * (1.05 + (spr * 0.005));
        
        if (skillT != null)
            val = skillT.getMpgr();
        
        ret = (value + val  + it);
        System.out.println("[MP REGEN RATE] : "+ret);
        return ret;
    }
      
    public int compSTR(String cName, Item i, SkillType skillT, Statistics wcs)
    {
        int ret = 0, skb = 0;
        String temp = null;
        int str = 0;
        
        if (i != null)
            str = i.getStr();
        
        if (skillT != null)
        {
            double dstr = skillT.getStr() * wcs.getStr();
            temp = String.valueOf(Math.floor(dstr));
            skb = Integer.parseInt(temp.substring(0, temp.length()-2));
        }
        
        ret = str + skb  + wcs.getStr();
        System.out.println("[STR] : "+ret);
        return ret;
    }
    
    public int compDEX(String cName, Item i, SkillType skillT, Statistics wcs)
    {
        Double d = new Double(0);
        
        int ret = 0, skb = 0;
        int dex = 0;
        
        if (i != null)
            dex = i.getDex();
        
        ret = dex + skb  + wcs.getDex();
        System.out.println("[DEX] : "+ret);
        return ret;
    }
    
    public int compINT(String cName, Item i, SkillType skillT, Statistics wcs)
    { 
        Double d = new Double(0);
        int ret = 0, skb = 0;
        int cInt = 0;
        
        if (i != null)
            cInt = i.getIint();
                        
        ret = cInt + skb  + wcs.getCInt();
        System.out.println("[INT] : "+ret);
        return ret;
    }
    
    public int compVIT(String cName, Item i, SkillType skillT, Statistics wcs)
    {
        int ret = 0, skb = 0;
        String temp = null;
        int vit = 0;
        
        if (i != null)
            vit = i.getVit();
        
        if (skillT != null)
        {
            double dvit = skillT.getVit() * wcs.getVit();
            temp = String.valueOf(Math.floor(dvit));
            skb = Integer.parseInt(temp.substring(0, temp.length()-2));
        }
        
        ret = vit + skb  + wcs.getVit();
        System.out.println("[VIT] : "+ret);
        
        return ret;
    }
    
    public int compSPR(String cName, Item i, SkillType skillT, Statistics wcs)
    {
        int ret = 0, skb = 0;
        String temp = null;
        int spr = 0;
        
        if (i != null)
            spr = i.getSpr();
        
        ret = spr + skb  + wcs.getSpr();
        
        System.out.println("[SPR] : "+ret);
        return ret;
    }
    
    public int compBATK(Statistics wcs)
    {
        double value = 0.0;
        String temp = null;
        int ret = 0;
        
        int str = wcs.getStr();
        value = (str + (5 * (str/5)));
        
        temp = String.valueOf(Math.floor(value));
        ret = Integer.parseInt(temp.substring(0, temp.length()-2));
        
        System.out.println("[BATK] : "+ret);
        return ret;
    }
    
    public int compBMATK(Statistics wcs)
    {
        double value = 0.0;
        String temp = null;
        int ret = 0;
        
        int intl = wcs.getCInt();
        value = ((intl * 2) + (10 * (intl/5)));
        
        temp = String.valueOf(Math.floor(value));
        ret = Integer.parseInt(temp.substring(0, temp.length()-2));
        System.out.println("[BMATK] : "+ret);
        return ret;
    }
    
    public int compATK(String cName, Item i, SkillType skillT, Statistics wcs)
    {
        Double d = new Double(0);
        int ret = 0, skb = 0;
        int atk = 0;
                
        int batk = this.compBATK(wcs); 
        if (i != null)
            atk = i.getAtk() * 1; //class modifier
        
        if (skillT != null)
        {
            d = Math.floor(skillT.getAtk() * wcs.getAtk());
            skb = d.intValue();
        }
        
        ret = batk + atk + skb ;
        System.out.println("[ATK] : "+cName+" "+ret);
        return ret;
    }
    
    public int compMATK(String cName, Item i, SkillType skillT, Statistics wcs)
    {
        Double d = new Double(0);
        int ret = 0, skb = 0, bls =  0;
        int matk = 0;
        
        int bmatk = this.compBMATK(wcs);
        if (i != null)
            matk = i.getMatk();
        
        if (skillT != null)
        {
            d = Math.floor(skillT.getMatk() * wcs.getMAtk());
            skb = d.intValue();
        }
        
        ret = bmatk + matk + skb ;
        System.out.println("[MATK] : "+cName+" "+ret);
        return ret;
    }
    
    public int compDEF(String cName, Item i, SkillType skillT, Statistics wcs)
    {
        Double d = new Double(0);
        int ret = 0, skb = 0;
        int def = 0;
        
        if (i != null)
            def = i.getDef();
        
        ret = def + skb  + wcs.getDef();
        System.out.println("[DEF] : "+cName+" "+ret);
        return ret;
    }
    
    public int compMOB(String cName, Item i, SkillType skillT)
    {
        int ret = 0, skb = 0;
        String temp = null;
        
        int mob = 0;
        
        if (i != null)
            mob = i.getMob();
        
        ret = mob + skb;
        System.out.println("[MOB] : "+cName+" "+ret);
        return ret;
    }
    
    public int compRES(String cName, Item i, SkillType skillT, Statistics wcs)
    {
        int ret = 0, skb = 0;
        String temp = null;
        
        int spr = wcs.getSpr();
        int res = 0;
        
        if (i != null)
            res = i.getRes();
        
        ret = spr + res + skb ;
        System.out.println("[RES] : "+cName+" "+ret);
        return ret;
    }
    
    public double compDodge(String cName, Item i, SkillType skillT, Statistics wcs)
    {
        double value = 0.0, ret = 0.0, skl = 0.0;
        double dodge = 0.0;
        
        if (i != null)
            dodge = i.getDodge();
        value = (1 + (wcs.getDex() / 5)) + this.compMOB(cName, i, skillT);
        ret = (value + dodge + skl ) / 100;
        System.out.println("[DODGE] : "+cName+" "+ret);
        return ret;
    }
    
    public double compBlock(String cName, Item i, SkillType skillT, Statistics wcs)
    {
        double value = 0.0, ret = 0.0, skb = 0;
        double block = 0.0;
        
        if (i != null)
            block = i.getBlock();
        
        value = (1 + (wcs.getStr() / 5)) + this.compMOB(cName, i, skillT);
        ret = (value + block + skb ) / 100;
        System.out.println("[BLOCK] : "+cName+" "+ret);
        return ret;
    }

    public double compACC(String cName, Item i, SkillType skillT, Statistics wcs)
    {
        //null skillT
        double value = 0.0, ret = 0.0, skb = 0;
        double acc = 0.0;
        
        int dex = wcs.getDex();
        if (i != null)
            acc = i.getAcc();
        
        value = (0.55 + (dex * 0.0025)) * 100;  //wcs.getARate();
        System.out.println(value+" "+acc+" "+skb);
        ret = value + acc + skb;
        
        System.out.println("[ACC] : "+ret);
        return ret;
    }
    
    //is used to subtract the crit stat after the pvp/curse battle
    public double compCRIT(String cName, Item i, SkillType skillT, Statistics wcs)
    {
        double value = 0.0, ret = 0.0, skb = 0;
        double crit = 0.0;
        
        int dex = wcs.getDex();
        int intl = wcs.getCInt();
        if (i != null)
            crit = i.getCrit();
             
        value = (0.01 + ((dex + intl) * 0.005)) * 100;      //wcs.getCritRate();  
        ret = value + crit + skb ;
        System.out.println("[CRIT] : "+cName+" "+ret);
        return ret;
    }
    
    public double compSPD(String cName, Item i, SkillType skillT, Statistics wcs)
    {
        double value = 0.0, ret = 0.0, skb = 0;
        double spd = 0.0;
        String temp = null;
        
        int dex = wcs.getDex();
        value = 0.5 + ((dex / 5) * 0.05);
        
        if (i != null)
            spd = i.getSpd();
        
        if (skillT != null)
        {
            double dspd = skillT.getSpd();
            temp = String.valueOf(Math.floor(dspd));
            skb = Integer.parseInt(temp.substring(0, temp.length()-2));
        }
        
        ret = value + spd + skb ;
        System.out.println("[SPD] : "+cName+" "+ret);
        return ret;
    }
    public Statistics getEQPBonus(Statistics wcs)
    {
        double acc=0, spd=0, ddg=0, blk=0, crt=0;
        int vit=0, atk=0,str=0, cint=0, spr=0, dex=0, matk=0, res=0, mob=0, def=0;
        
        System.out.println(wcs.getCharacterName());
        
        Item itm = new Item ();
        Vector<Item> kVec = itm.viewCharItems(wcs.getCharacterName());
        Statistics ret = new Statistics();
        
        if(!kVec.isEmpty())
        {
            Iterator it = kVec.iterator();      
            
            while(it.hasNext())
            {
                Item i = (Item)it.next();
                
                if (!i.getItemType().startsWith("CON"))
                {
                    if (i.getVit() > 0)
                        vit += i.getVit();
                    if (i.getAcc() > 0)
                        acc += i.getAcc();
                    if (i.getAtk() > 0)
                        atk += i.getAtk();
                    if (i.getStr() > 0)
                        str += i.getStr();
                    if (i.getSpr() > 0)
                        spr += i.getSpr();
                    if (i.getSpd() > 0)
                        spd += i.getSpd();
                    if (i.getRes() > 0)
                        res += i.getRes();
                    if (i.getMob() > 0)
                        mob += i.getMob();
                    if (i.getMatk() > 0)
                        matk +=  i.getMatk() * 1;
                    if (i.getIint() > 0)
                        cint += i.getIint();
                    if (i.getDodge() > 0)
                        ddg += i.getDodge();
                    if (i.getDex() > 0)
                        dex += i.getDex();
                    if (i.getDef() > 0)
                        def += i.getDef();
                    if (i.getCrit() > 0)
                        crt += i.getCrit();
                    if (i.getBlock() > 0)
                        blk += i.getBlock();
                    
                    //System.out.println("["+i.getItemName()+"]");
                }
            }
            ret.setStr(str);
            ret.setVit(vit);
            ret.setDex(dex);
            ret.setSpr(spr);
            ret.setCInt(cint);

            ret.setARate(acc);
            ret.setCritRate(crt);
            ret.setBRate(blk);
            ret.setDRate(ddg);
            ret.setMobility(mob);

            ret.setSpd(spd);
            ret.setDef(def);
            ret.setRes(res);
            ret.setAtk(atk);
            ret.setMAtk(matk);
            ret.setStatType(1);
            ret.setCharacterName(wcs.getCharacterName());
        }
        return ret;
    }
    
    public Statistics getBlessBonus(WispCharacter wc)
    {
        Double d1 = new Double(0);
        Double d2 = new Double(0);
        Statistics ret = new Statistics();
        Blurse blurse = new Blurse();
        
        double acc=0, spd=0, ddg=0, blk=0, crt=0, mpr=0, hpr=0;
        int vit=0, atk=0, str=0, cint=0, spr=0, dex=0, matk=0, res=0, mob=0, def=0, chp=0, cmp=0, mhp=0, mmp=0;
        System.out.println(wc.getCharactername());
        Vector<Blurse> blVec = blurse.viewBlurse(wc.getCharactername());
        if (blVec != null)
        {
            God g = new God();
            Vector<God> bVec = new Vector(); 
            bVec = g.viewCharBless(wc.getCharactername());
            
            Iterator it = bVec.iterator();
            while(it.hasNext())
            {
                God gd = new God();           
                gd = (God)it.next();
       
                d1 = gd.getVal1();
                d2 = gd.getVal2();

                if (gd.getAt1().equals("str"))
                    str = d1.intValue();
                else if (gd.getAt2().equals("str"))
                    str = d2.intValue();
                if (gd.getAt1().equals("vit"))
                    vit = d1.intValue();
                else if (gd.getAt2().equals("vit"))
                    vit = d2.intValue();
                if (gd.getAt1().equals("int"))
                    cint = d1.intValue();
                else if (gd.getAt2().equals("int"))
                    cint = d2.intValue();
                if (gd.getAt1().equals("dex"))
                    dex = d1.intValue();
                else if (gd.getAt2().equals("dex"))
                    dex = d2.intValue();
                if (gd.getAt1().equals("spr"))
                    spr = d1.intValue();
                else if (gd.getAt2().equals("spr"))
                    spr = d2.intValue();
                
                if (gd.getAt1().equals("atk"))
                    atk = d1.intValue();
                else if (gd.getAt2().equals("atk"))
                    atk = d2.intValue();
                if (gd.getAt1().equals("matk"))
                    matk = d1.intValue();
                else if (gd.getAt2().equals("matk"))
                    matk = d2.intValue();
                if (gd.getAt1().equals("def"))
                    def = d1.intValue();
                else if (gd.getAt2().equals("def"))
                    def = d2.intValue();
                if (gd.getAt1().equals("res"))
                    res = d1.intValue();
                else if (gd.getAt2().equals("res"))
                    res = d2.intValue();
                if (gd.getAt1().equals("mob"))
                    mob = d1.intValue();
                else if (gd.getAt2().equals("mob"))
                    mob = d2.intValue();
                
                if (gd.getAt1().equals("crit"))
                    crt = d1.intValue();
                else if (gd.getAt2().equals("crit"))
                    crt = d2.intValue();
                if (gd.getAt1().equals("block"))
                    blk = d1.intValue();
                else if (gd.getAt2().equals("block"))
                    blk = d2.intValue();
                if (gd.getAt1().equals("dodge"))
                    ddg = d1.intValue();
                else if (gd.getAt2().equals("dodge"))
                    ddg = d2.intValue();
                if (gd.getAt1().equals("acc"))
                    acc = d1.intValue();
                else if (gd.getAt2().equals("acc"))
                    acc = d2.intValue();
                if (gd.getAt1().equals("spd"))
                    spd = d1.intValue();
                else if (gd.getAt2().equals("spd"))
                    spd = d2.intValue();
                
                if (gd.getAt1().equals("chp"))
                    chp = d1.intValue();
                else if (gd.getAt2().equals("chp"))
                    chp = d2.intValue();
                if (gd.getAt1().equals("cmp"))
                    cmp = d1.intValue();
                else if (gd.getAt2().equals("cmp"))
                    cmp = d2.intValue();
                if (gd.getAt1().equals("mhp"))
                    mhp = d1.intValue();
                else if (gd.getAt2().equals("mhp"))
                    mhp = d2.intValue();
                if (gd.getAt1().equals("mmp"))
                    mmp = d1.intValue();
                else if (gd.getAt2().equals("mmp"))
                    mmp = d2.intValue();
                if (gd.getAt1().equals("hpr"))
                    hpr = d1.intValue();
                else if (gd.getAt2().equals("hpr"))
                    hpr = d2.intValue();
                if (gd.getAt1().equals("mpr"))
                    mpr = d1.intValue();
                else if (gd.getAt2().equals("mpr"))
                    mpr = d2.intValue();
                
                ret.setStr(str);
                ret.setVit(vit);
                ret.setDex(dex);
                ret.setSpr(spr);
                ret.setCInt(cint);

                ret.setARate(acc);
                ret.setCritRate(crt);
                ret.setBRate(blk);
                ret.setDRate(ddg);
                ret.setMobility(mob);

                ret.setSpd(spd);
                ret.setDef(def);
                ret.setRes(res);
                ret.setAtk(atk);
                ret.setMAtk(matk);
                ret.setStatType(1);
            
                wc.setCHP(wc.getCHP()+chp);
                wc.setCMP(wc.getCMP()+cmp);
                wc.setMHP(wc.getMHP()+mhp);
                wc.setMMP(wc.getMMP()+mmp);
                ret.setHpGR(hpr);
                ret.setMpGR(mpr);
                
                Iterator bIt = blVec.iterator();
                while (bIt.hasNext())
                {
                    Blurse b = (Blurse)bIt.next();
                    if (b.getGodname().equals(gd.getBless()))
                    {   
                        b.editBlurse(wc.getCharactername(), b.getGodname(), b.getTurn()-1, b.getBattle()-1);
                        if (b.getBattle() < 1)
                            b.deleteBlurse(b); 
                        break;
                    }
                     
                }      
                          
            }
        }
        return ret;
    }
}
